<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>订单列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/weadmin.css">
    <link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.1/lib/theme-chalk/index.css">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../../../../assets/js/vendor/vue.min.js"></script>
    <script src="../../../../assets/js/vendor/jquery-3.3.1.min.js"></script>
    <script src="../../../../assets/js/plugins/utils.js"></script>
    <script src="../../static/js/admin.js"></script>
    <script src="https://unpkg.com/element-ui@2.13.1/lib/index.js"></script>
</head>

<body>
<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">分类管理</a>
        <a><cite>分类列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="weadmin-body" id="cateItem">

    <div class="weadmin-block">
        <button class="layui-btn" onclick="WeAdminShow('添加分类','./add.html', 600, 400)"><i class="layui-icon"></i>添加</button>
        <span class="fr" style="line-height:40px">共有数据：{{page.total}} 条</span>
    </div>
    <table class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>分类名称</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(cate,index) in cateList"  v-if="cateList!=''">
            <td>{{index+1}}</td>
            <td>{{cate.name}}</td>
            <template v-if="cate.flag==1">
                <td class="td-manage">
                    此分类不能操作
                </td>
            </template>
            <template v-else>
                <td class="td-manage">
                    <a title="删除" @click="deleteProduct(cate.id)" href="javascript:;">
                        <i class="layui-icon">&#xe640;</i>
                    </a>
                </td>
            </template>

        </tr>
        </tbody>
    </table>
    <div class="block">
        <el-pagination
                @current-change="handleCurrentChange"
                :current-page.sync="page.pageNum"
                :page-size="page.pageSize"
                :hide-on-single-page="true"
                layout="total, prev, pager, next"
                :total="page.pages">
        </el-pagination>
    </div>

</div>
<script type="text/javascript">
    var cate_list = new Vue({
        el: "#cateItem",
        data: {
            cateList: [],
            page: {"pageNum": 1, "pageSize": 10, "pages": 0, "total": 0}
        },
        mounted: function () {
            this.getCateList();
        },
        methods: {
            getCateList() {
                $.ajax({
                    url: "/admin/product_category/"+this.page.pageNum,
                    type: "get",
                    headers: {
                        "Authorization": "Bearer " + handleLocalStorage("get", "token")
                    },
                    success: function (response) {
                        if (response.code == 200) {
                            cate_list.cateList=response.data.list;
                            cate_list.page.pageNum = response.data.pageNum;
                            cate_list.page.pageSize = response.data.pageSize;
                            cate_list.page.pages = response.data.pages;
                            cate_list.page.total = response.data.total;
                            console.log(response);
                        }else {
                        }
                    },
                    error: function (error) {
                        alert("服务器错误");
                    }

                });
            },
            deleteProduct(id) {
                var t = this;
                $.ajax({
                    url: "/admin/delete_product/"+id,
                    type: "GET",
                    headers: {
                        "Authorization": "Bearer " + handleLocalStorage("get", "token")
                    },
                    success: function (response) {
                        alert(response.message);
                        if (response.code == 200) {
                            cate_list.getCateList();
                        }
                    },
                    error: function (error) {
                        alert("服务器错误");
                    }
                });
            },
            handleCurrentChange(val) {
                this.page.pageNum = val;
                this.getCateList();
            }
        }
    });
</script>
</body>

</html>